<script setup>
  import { inject, ref, onUpdated } from 'vue'
  // import useWebsiteStore from '@/store/websiteStore'
  // const websiteStore = useWebsiteStore()

  // const { isShow, setIsShow } = inject('dialog-visible')
  // const { url } = inject('dialog-url')
  const isShow=ref(false)
  const url = ref('')

  const isSubmit = ref(false)

  const handleAddClick = async () => {
    isSubmit.value = true
    const result = await myApi.sendUrl(url.value)
    if (result.msg) {
      myApi.alert(result.msg)
      isSubmit.value = false
    } else {
      // websiteStore.add(result)
      isSubmit.value = false
      // setIsShow(false)
    }

    url.value = ''
  }

  const handleCancelClick = () => {
    // setIsShow(false)
    url.value = ''
  }

  // onUpdated(() => {
  //   url.value = ''
  // })
</script>

<template>
  <div class="dialog-wrap" v-if="isShow">
    <div class="content">
      <div class="input">
        <input type="text" v-model="url" @keyup.enter="handleAddClick" placeholder="请输入网址..." :disabled="isSubmit">
      </div>
      <div class="btns">
        <button @click="handleAddClick" :disabled="isSubmit">添加</button>
        <button @click="handleCancelClick" :disabled="isSubmit">取消</button>
      </div>
    </div>
  </div>
</template>

<style >
</style>
